package com.whity.towerdefense.model;

import java.util.HashMap;

import org.xmlpull.v1.XmlPullParser;
import android.util.Log;

public class TowerFactory
{
	// =============================================================
	// Private attributs
	
	private static final String					TAG = "com.djm.test03.model";
	
	private static HashMap<String, TowerType> 	m_TowerTypes = new HashMap<String, TowerType>();
	private static int							m_CountCreatedType = 0;
	
	// =============================================================
	// Public functions :
	
	/*
	public UnitFactory()
	{
		
	}*/
	
	public static Tower CreateTower(String p_ID, int p_X, int p_Y)
	{
		TowerType towerType = null;
		if((towerType = m_TowerTypes.get(p_ID)) != null)
		{
			Tower res = towerType.CreateTower(p_X, p_Y);
			return res;
		}
		return null;
	}
	
	public static TowerType GetTowerType(String p_ID)
	{
		return m_TowerTypes.get(p_ID);
	}
	
	public static void SetTowerType(String p_ID, TowerType p_Type)
	{
		m_TowerTypes.put(p_ID, p_Type);
	}
	
	public static String CreateNewType(XmlPullParser p_XmlParser) throws ParsingException
	{
		if(!p_XmlParser.getName().equals("TowerType"))
    	{
			Log.w(TAG, "Can't create a Tower type with an Xml item : " + p_XmlParser.getName());
			throw(new ParsingException("Can't create a Tower type with an Xml item : " + p_XmlParser.getName()));
		}
		
		// We get the new Id of this new type
		String NewTypeId = "AutomaticTowerType" + m_CountCreatedType;
		m_CountCreatedType++;
		
		// Create the new Type
		TowerType newType;
		newType = new TowerType(p_XmlParser);
		m_TowerTypes.put(NewTypeId, newType);
		
		return NewTypeId;
	}
	
	// =============================================================
}
